#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.${parentArtifactId}.modules.tool;

import ${package}.${parentArtifactId}.libcommon.bean.R;
import ${package}.${parentArtifactId}.modules.lock.model.User;
import ${package}.${parentArtifactId}.modules.lock.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Api(tags = "分布式锁测试")
@RestController
@RequestMapping("/api/tool/lock")
public class LockTestController {

    @Autowired
    UserService userService;

    private static final Random RANDOM = new Random();
    ExecutorService executorService = Executors.newFixedThreadPool(3);

    @ApiOperation("简单测试1")
    @GetMapping("/simple1Test")
    public R<Void> simple1Test(){
        Runnable task = () -> userService.simple1();
        for (int i = 0; i < 20; i++) {
            executorService.submit(task);
        }
        return R.ok();
    }

    @ApiOperation("简单测试2")
    @GetMapping("/simple2Test")
    public R<Void> simple2Test(){
        Runnable task = () -> userService.simple2();
        for (int i = 0; i < 20; i++) {
            executorService.submit(task);
        }
        return R.ok();
    }

    @ApiOperation("spel1Test")
    @GetMapping("/spel1Test")
    public R<Void> spel1Test(){
        Runnable task = () -> userService.method1(new User(RANDOM.nextLong(), "gacl"));
        for (int i = 0; i < 20; i++) {
            executorService.submit(task);
        }
        return R.ok();
    }

    @ApiOperation("spel2Test")
    @GetMapping("/spel2Test")
    public R<Void> spel2Test(){
        Runnable task = () -> userService.method2(new User(RANDOM.nextLong(), "gacl"));
        for (int i = 0; i < 20; i++) {
            executorService.submit(task);
        }
        return R.ok();
    }
}
